package algorithm;

/**
 * @description: 找最大值，最小值，平均，总和
 * @author: apple
 * @date:  2021/11/18 2:27 下午
 * @version 1.0
 **/
public class FindMaxMin {

    public static void main(String[] args) {

        int[] nums = {8,2,6,1,12,5,9};

        // 找最大值
        int max = nums[0];

        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > max) {
                max = nums[i];
                continue;
            }
        }

        // 找最小值
        int min = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] < min) {
                min = nums[i];
                continue;
            }
        }

        // 算总和
        int sum = 0;
        for (int i = 1; i < nums.length; i++) {
           sum += nums[i];
        }
        // 算平均
        double avg = sum / nums.length;

        System.out.println("最大值是：" + max);
        System.out.println("最小值是：" + min);
        System.out.println("总和：" + sum);
        System.out.println("平均" + avg);
    }
}
